package com.roads.project.controller;

import com.roads.common.core.controller.BaseController;
import com.roads.common.core.domain.AjaxResult;
import com.roads.common.utils.SecurityUtils;
import com.roads.project.domain.ProInstitution;
import com.roads.project.domain.bid.BidSelect;
import com.roads.project.service.IBidService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName BidController
 * @Description 标段controller
 * @Author nhp
 * @Date 2021/11/30 0030 14:58
 * @Version 1.0.0
 **/
@RestController
@RequestMapping("/project/bid")
public class BidController extends BaseController {

    @Autowired
    private IBidService bidService;

    /**
     * group分组下拉框 由项目和机构组成
     * 项目标段或分包下拉框
     * 1.添加所有标段机构
     * 2.分包机构如果共享清单就不展示分包机构
     * @return 标段分部机构集合
     */
    @GetMapping("/selectProjectBidOrBranch")
    public AjaxResult selectProjectBidOrBranch() {
        String userName = getUsername();
        boolean isAdmin = SecurityUtils.isAdmin(getUserId());
        List<BidSelect> list = bidService.selectProjectBidOrBranch(userName, isAdmin);
        return AjaxResult.success(list);
    }

    /**
     * group分组下拉框 由项目和机构组成
     * 项目标段分包下拉框 -- 所有机构类型为B和F
     * @return 标段分部机构集合
     */
    @GetMapping("/selectProjectBidBranch")
    public AjaxResult selectProjectBidBranch() {
        String userName = getUsername();
        boolean isAdmin = SecurityUtils.isAdmin(getUserId());
        List<BidSelect> list = bidService.selectProjectBidBranch(userName, isAdmin);
        return AjaxResult.success(list);
    }

    /**
     * group分组下拉框 由项目和机构组成
     * 项目标段下拉框 -- 所有机构类型
     * @return 项目标段机构集合
     */
    @GetMapping("/selectProjectBid")
    public AjaxResult selectProjectBid() {
        String userName = getUsername();
        boolean isAdmin = SecurityUtils.isAdmin(getUserId());
        List<BidSelect> list = bidService.selectProjectBid(userName, isAdmin);
        return AjaxResult.success(list);
    }

    /**
     * 普通下拉框 所有机构类型为B和F
     * @return 标段分部机构集合
     */
    @GetMapping("/selectBidBranch")
    public AjaxResult selectBidBranch() {
        String userName = getUsername();
        boolean isAdmin = SecurityUtils.isAdmin(getUserId());
        List<ProInstitution> list = bidService.selectBidBranch(userName, isAdmin);
        return AjaxResult.success(list);
    }

    /**
     * 普通下拉框 该项目下的所有机构
     * @return 标段分部机构集合
     */
    @GetMapping("/selectBidByProjectId/{projectId}")
    public AjaxResult selectBidByProjectId(@PathVariable("projectId")Integer projectId) {
        ProInstitution search = new ProInstitution();
        search.setProjectId(projectId);
        if (!SecurityUtils.isAdmin(getUserId())) {
            search.setCreateBy(getUsername());
        }
        List<ProInstitution> list = bidService.selectBidByProjectId(search);
        return AjaxResult.success(list);
    }

    /**
     * 监理标段group分组下拉框 由项目和机构组成
     * 项目标段分包下拉框 -- 所有机构类型为D,J,Z,A
     * @return 监理标段机构集合
     */
    @GetMapping("/selectProjectSupervisorBid")
    public AjaxResult selectProjectSupervisorBid() {
        String userName = getUsername();
        boolean isAdmin = SecurityUtils.isAdmin(getUserId());
        List<BidSelect> list = bidService.selectProjectSupervisorBid(userName, isAdmin, null);
        return AjaxResult.success(list);
    }

    /**
     * 代建标段group分组下拉框 由项目和机构组成
     * 项目标段分包下拉框 -- 所有机构类型为A
     * @return 代建标段机构集合
     */
    @GetMapping("/selectProjectAgencyBid")
    public AjaxResult selectProjectAgencyBid() {
        String userName = getUsername();
        boolean isAdmin = SecurityUtils.isAdmin(getUserId());
        List<BidSelect> list = bidService.selectProjectSupervisorBid(userName, isAdmin, "6");
        return AjaxResult.success(list);
    }

    /**
     * 监理普通下拉框--主要用于监理计量新增
     * @return 监理机构集合
     */
    @GetMapping("/dropdownSupervisorBid")
    public AjaxResult dropdownSupervisorBid() {
        String userName = getUsername();
        List<ProInstitution> list = bidService.selectSupervisorBid(userName);
        return AjaxResult.success(list);
    }

    /**
     * 代建普通下拉框--主要用于代建计量新增
     * @return 代建机构集合
     */
    @GetMapping("/dropdownAgencyBid")
    public AjaxResult dropdownAgencyBid() {
        String userName = getUsername();
        List<ProInstitution> list = bidService.selectAgencyBid(userName);
        return AjaxResult.success(list);
    }

}
